<?php 
$i=isset($_GET['i'])?$_GET['i']:1;
$page_group_id=$page=='tin-tuc'?3:4;
$query="SELECT COUNT(*) FROM tbl_page WHERE page_group_id=$page_group_id AND page_status=1";
$count=Db::mysql_query($query,FETCH_MODE_CELL);
if($i<1)
	Common::header_location(null,"index.php?page=$page&i=1");
else if($i>ceil($count/ROW_PER_PAGE))
	Common::header_location(null,"index.php?page=$page&i=".ceil($count/ROW_PER_PAGE));
$table=Db::mysql_query("SELECT * FROM tbl_page WHERE page_group_id=$page_group_id AND page_status=1 ORDER BY page_id DESC LIMIT ".(($i-1)*ROW_PER_PAGE).",".ROW_PER_PAGE,FETCH_MODE_TABLE);
?>
<style>
.entry img{width:180px;height:auto}
</style>
<?php foreach($table as $key=>$row){
	$page_title="Mã số: ".$row['page_title']."<span>Ngày đăng: ".date('d/m/Y').". Trạng thái: ".($row['page_sent']==1?'đã':'chưa')." giao.</span>";
?>
	<div class="post hentry uncustomized-post-template">
	<div class="post_bottom">
	<h2 class="post-title entry-title">
		<a href="?page=<?php echo $row['page_name']?>&id=<?php echo $row['page_id']?>&group_id=<?php echo $page_group_id;?>">
			<?php echo $page_title;?>
		</a>
	</h2>
	<div class="post_date">
		<span><?php echo $row['page_title'];?></span> (<?php echo date('d/m/Y');?>)
	</div>
	<div class="post-header-line-1"></div>
	<?php if($login==1 && $mode=='edit'){?>
		<input type='button' value='Xóa' style='float:right' class='i-delete' link='page=_delete&id=<?php echo $row['page_id']?>'/>
	<?php }?>
	<div class="entry i-update" link='page=_update-<?php echo $page_group_id==3?'news':'class';?>&id=<?php echo $row['page_id']?>&group_id=<?php echo $page_group_id?>'>
		<div class='quote'>
			<?php echo $row['page_quote_'.$language];?>
		</div>
		<div style="clear: both;"></div>
	</div>
	
	<div class="read_comments"><a href="?page=<?php echo $row['page_name']?>&id=<?php echo $row['page_id']?>&group_id=<?php echo $page_group_id;?>">Xem chi tiết</a></div>
	<div class="endline"></div>
	</div>
	</div>
<?php }?>


<div class="read_comments">
	<div id='pagination'>
		<?php if($i>1){?><span id='prev' onclick="window.location='index.php?page=<?php echo $page;?>&i=<?php echo $i-1?>'" title='Trang trước'></span><?php }?>
		
		<?php 		
		$min=$i-5;
		$max=$i+4;
		if($min<0)
		{
			$max+=(0-$min+1);
			$min=1;
		}
		else if($max>ceil($count/ROW_PER_PAGE))
		{
			$min-=($max-ceil($count/ROW_PER_PAGE));
			$max=ceil($count/ROW_PER_PAGE);
		}
		if($max>ceil($count/ROW_PER_PAGE))
			$max=ceil($count/ROW_PER_PAGE);
		?>
		
		<?php for($j=$min;$j<=$max;$j++){?>
			<?php if($i==$j){?>
			<a id='current'><span class='number' ><?php echo $j;?></span></a>
			<?php }else{?>
			<span class='number' onclick="window.location='index.php?page=<?php echo $page?>&i=<?php echo $j?>'" ><?php echo $j;?></span>
			<?php }?>
		<?php }	?> 
		
		<?php if($i<ceil($count/ROW_PER_PAGE)){?><span onclick="window.location='index.php?page=<?php echo $page?>&i=<?php echo $i+1?>'" title='Trang tiếp theo' id='next'></span><?php }?>
	</div>
	
	<a href="#body">Về đầu trang</a>
</div>

